package vues;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Stroke;
import java.awt.geom.Rectangle2D;

import sourceCode.Tobogan;


public class VueTobogan extends Vue {

    private Tobogan tobogan;
    private VueAeroport vueAeroport;

    private Color couleurNormal = new Color(130, 130, 250);
    private Color couleurSurbrillance = new Color(200, 0, 0);
    private Color couleurSelectionne = new Color(0, 130, 250);

    private Rectangle2D.Double rectangleTobogan;

    private int longueurTobogan = 28;
    private int hauteurTobogan = 8;

    public VueTobogan(VueAeroport v, Tobogan t) {
        super();
        this.tobogan = t;
        this.vueAeroport = v;
        Point centre = this.vueAeroport.convertCoordonnesToPixels(tobogan.getCoordonnees());
        this.rectangleTobogan =
                new Rectangle2D.Double(centre.getX() + VueRail.largeurRail, centre.getY() - (this.hauteurTobogan / 2),
                                       this.longueurTobogan, this.hauteurTobogan);
    }


    public boolean estCliquee(int x, int y) {
        return this.rectangleTobogan.contains(x, y);
    }

    @Override
    public void dessiner(Graphics g) {
        Color cTemp = g.getColor();
        g.setColor(this.couleurNormal);
        g.fillRect((int)rectangleTobogan.x, (int)rectangleTobogan.y, (int)rectangleTobogan.width,
                   (int)rectangleTobogan.height);
        if (estSelectionnee()) {
            g.setColor(this.couleurSelectionne);
            Graphics2D g2d = (Graphics2D)g;
            float dash1[] = { 3.5f };
            Stroke rectStroke = new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, dash1, 0.0f);
            g2d.setStroke(rectStroke);
            g2d.drawRect((int)this.rectangleTobogan.x, (int)this.rectangleTobogan.y, (int)this.rectangleTobogan.width,
                         (int)this.rectangleTobogan.height);
            g2d.setStroke(new BasicStroke()); //on restaure le style par defaut
        }

        if (vueAeroport.getChoixTobogan()) {
            g.setColor(this.couleurSurbrillance);
            Graphics2D g2d = (Graphics2D)g;
            float dash1[] = { 3.5f };
            Stroke rectStroke = new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10f, dash1, 0.0f);
            g2d.setStroke(rectStroke);
            g2d.drawRect((int)this.rectangleTobogan.x, (int)this.rectangleTobogan.y, (int)this.rectangleTobogan.width,
                         (int)this.rectangleTobogan.height);
            g2d.setStroke(new BasicStroke()); //on restaure le style par defaut
        }
        g.setColor(cTemp);
        return;
    }

    @Override
    public String getType() {
        return "VueTobogan";
    }

    public Tobogan getTobogan() {
        return this.tobogan;
    }
}
